<?php
class Customer extends CI_Controller {
	
	function __construct(){
		// Call the Model constructor
		parent::__construct();
		$this->load->model('booking');
	}
	function index(){
		$this->load->view('customer_view');
	}
	function check_availability(){
		$date = $this->input->post('check_in_date');
		$branch = $this->input->post('branch');
		$rooms = $this->input->post('no_rooms');
		$num_rooms = $this->booking->get_availability($date,$branch)+$rooms;
		if($num_rooms <= 20){
			echo true;
		}else{
			echo false;
		}
	}
	
	function booking_view($date,$night,$branch,$rooms){
		$data['rooms']=$rooms;
		$data['branch']=$branch;
		$data['date']=$date;
		$data['night']=$night;
		$this->load->view('booking_view',$data);
	}
	
	function keep_booking($branch,$date,$night,$rooms){
		$fname = $this->input->post('fname');
		$lname = $this->input->post('lname');
		$email = $this->input->post('email');
		$tel = $this->input->post('tel');
		$address = $this->input->post('address');
		$credit = $this->input->post('credit');
		
		$date_out = date('Y-m-d',strtotime($date."+".$night." day"));
		
		$data = array('firstname' => $fname, 'lastname' => $lname, 'address' => $address, 'email' => $email, 'tel' => $tel, 'credit_card' => $credit);
		$reserve_data = array('branch_id' => $branch, 'check_in_date' => $date, 'check_out_date' => $date_out, 'no_of_room' => $rooms, 'price' => $rooms*$night*200);
		
		$reserve_id = $this->booking->insert_booking($data,$reserve_data);
		$get_room = $this->booking->get_room($branch,$date,$date_out);
		echo $get_room;
		$room_result = $get_room;
		$this->booking->room_reserve($reserve_id,$rooms,$room_result);
		
	}
}
?>